
#include <iostream>
#include "CustomAnimController.h"

#include "InputsManager.h"
#include "CharacterController.h"

#include "SpriteHelperLoader.h"

#include <vector>


GenericAnimController::GenericAnimController(BasicCharacterController* controller, const char* _fileName, const char* CharacterName ):
	BasicAnimController(controller)
{
	std::string NameOfAnim[BASIC_ANIM_COUNT] = {
												"_idle",
												"_jump",
												"_sprint_jump",
												"_air_down",
												"_break",
												"_walk",
												"_sprint"
											   };
	
	
	SpriteHelperLoader sh( _fileName );



	// graphics

	std::vector<std::string> animFrames;

	for( int i=0; i< BASIC_ANIM_COUNT; i++ )
	{
		std::string animName = std::string(CharacterName) + NameOfAnim[i];
		std::vector<std::string> _Frames = sh.frameListWithAnimName( animName );

		for(int j=0; j<_Frames.size(); j++)
		{
			animFrames.push_back( _Frames[j] );
		}
	}

    CCAction* animAction;
	mImg = sh.animSpriteWithUniqueName(animFrames,
                                         ccp(150,200),
                                         NULL,
                                         0.1f,
                                         0, //number of repeats - if its 0 the animation will run forever or until you stop it
                                         &animAction);
    


    // ANIMATION
    
	for( int i=0; i< BASIC_ANIM_COUNT; i++ )
	{
		std::string animName = std::string(CharacterName) + NameOfAnim[i];

		mAnimList[i] =  sh.actionForAnimName( animName, 0.1f );
		mAnimList[i]->retain();
	}

	PlayAnim( ANIM_IDLE );
}